<?php
/**
 * The basic page class from which all pages are descended.
 */
class Page {
    /**
     * The request object.
     * @var Request
     */
	protected $request;
    /**
     * The response object.
     * @var Response
     */
	protected $response;
    /**
     * The view object.
     * @var View
     */
    protected $view = null;

    /**
     * Construct the object.
     * @param Request $request
     * @param Response $response
     */
	public function __construct(Request $request, Response $response) {
		$this->request = $request;
		$this->response = $response;
	}

    /**
     * Set the view object.
     * @param View $view
     */
    public function setView(View $view) {
        $this->view = $view;
        if($this->view->getTemplate() == '') {
            $this->view->setTemplate(get_class($this));
	}
	$this->view->baseUrl = $this->request->getBaseUrl();
    }

    /**
     * Get the view object.
     * @return View
     */
    public function getView() {
        if($this->view === null) {
            $this->setView(new View());
        }
        return $this->view;
    }

    /**
     * Method to run before the page is dispatched. Override this in descendents.
     */
    public function preDispatch() {
    }

    /**
     * Method to run after the page is dispatched. Override this in descendents.
     */
    public function postDispatch() {
    }

    /**
     * Display method. This is the default method.
     */
	public function display() {
	}
}
?>
